document.addEventListener('DOMContentLoaded', function() {
    //右侧固定导航栏的页面跟随
    var banner = document.querySelector('.banner');
    var Top = 215 + banner.offsetHeight;
    var article = document.querySelector('.article');
    article.style.top = Top + 'px';
    document.addEventListener('scroll', function() {
        if (window.pageYOffset >= Top - 150) {
            article.style.position = 'fixed';
            article.style.top = 150 + 'px';
        } else {
            article.style.position = 'absolute';
            article.style.top = Top + 'px';
        }
    })
    var goBack = document.querySelector('.goBack');
    goBack.addEventListener('click', function() {
        animate(window, 0);
    });
    // 动画函数
    function animate(obj, target, callback) {
        clearInterval(obj.timer);
        obj.timer = setInterval(function() {
            var step = (target - window.pageYOffset) / 10;
            step = step > 0 ? Math.ceil(step) : Math.floor(step);
            if (window.pageYOffset == target) {
                clearInterval(obj.timer);
                callback && callback();
            }
            window.scroll(0, window.pageYOffset + step);
        }, 15);
    }
})